import java.io.File;

import javax.swing.filechooser.FileFilter;


/**
 * @author Shangru Li
 * this class extends the FileFilter and works with the class myChooser 
 * this class is used for filter showing only the file with desired suffix and directory  
 *
 */
public class neededFil extends FileFilter {
    String ext; // a string for the recording the extension that can pass the filter
    neededFil(String ext){ // constructor that needs a string parameter 
    	this.ext=ext;
    	
    }
    
	public boolean accept(File f) {//check whether to manifest a certain file
        if(f.isDirectory()) // if the file is a directory
		return true; // it is acceptable
        
        String fileName=f.getName(); 
        int index=fileName.lastIndexOf('.');
        if (index>0&index<(fileName.length()-1)){ //to catch the extension of the file
        	String extension=fileName.substring(index+1).toLowerCase();
        	if (extension.equals(ext)) // if the extension of this file is the same as the extension that can pass
        		return true; // it is also acceptable
        }
        
		return false;
	}


	public String getDescription() {
		// TODO Auto-generated method stub
		return "*"+ext; // change the description with the extension that can pass
	}

}
